#include<bits/stdc++.h>
#include "graph.h"

std::vector<int> cc[205],dd[205];
int dl[205],nm,bbs,ff[205];

void dfs(int &x,int f){
	int pr=0;if(f)pr=LastRoad();
	if(Color()==2)x=0;
	else if(Color()==3)x=1e9;
	else{x=++nm;dl[x]=dl[f]+1;ff[x]=f;
		int dg=NumberOfRoads();
		for(int i=1;i<=dg;i++){
			cc[x].push_back(0);
			dd[x].push_back(0);
			if(i!=pr)Move(i,2),
				dfs(cc[x][i-1],x);
		}
	}//std::cout<<"now at: "<<x<<"\n";
	if(pr)Move(pr,(x==0?2:3));
}

void solve(int x,int f,int id){//std::cout<<"now at: "<<x<<"\n";
	int pr=0;if(f)pr=LastRoad();
	if(!x){dd[f][id-1]+=bbs*(Color()-1);Move(pr,Color());return;}
	int dg=NumberOfRoads();
	for(int i=1;i<=dg;i++){
		if(i==pr||cc[x][i-1]==1e9)continue;
		else Move(i,(dl[x]/bbs)%3+1),
			solve(cc[x][i-1],x,i);
	}if(pr)Move(pr,(dl[x]/bbs)%3+1);
}

int dx[205][205],cnds[205];int ssum=0;

void Inspect(int r){
	int rt=0;dfs(rt,0);bbs=1;//std::cout<<"track complete\n";
	for(int i=0;i<=4;i++)solve(rt,0,0),bbs*=3;//std::cout<<"track complete\n";
	memset(dx,0x3f,sizeof(dx));
//	for(int i=1;i<=nm;i++)std::cout<<ff[i]<<"\n",ssum+=cc[i].size();
	for(int i=1;i<=nm;i++)
		for(int j=0;j<cc[i].size();j++){
			if(!cc[i][j]&&dd[i][j]<dl[i]){cc[i][j]=i;
				while(dl[cc[i][j]]>dd[i][j])cc[i][j]=ff[cc[i][j]];
			}if(cc[i][j]<1e9&&cc[i][j]>0)dx[i][cc[i][j]]=dx[cc[i][j]][i]=1;//std::cout<<i<<" "<<cc[i][j]<<"\n";
		}
	for(int k=1;k<=nm;k++)
		for(int i=1;i<=nm;i++)
			for(int j=1;j<=nm;j++)
				dx[i][j]=std::min(dx[i][j],dx[i][k]+dx[k][j]);
	for(int i=1;i<=nm;i++)
		for(int j=i+1;j<=nm;j++)
			if(dx[i][j]<=r)cnds[dx[i][j]]++;
	for(int i=1;i<=r;i++)Answer(i,cnds[i]);return;
}
